#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
PyQt5 tutorial 

In this example, we determine the event sender
object.

author: py40.com
last edited: 2017年3月
"""
import sys
from PyQt5.QtWidgets import QWidget, QCheckBox, QApplication
from PyQt5.QtCore import Qt


class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        self.initUI()
        
        
    def initUI(self):      

        self.cb = QCheckBox('Change title', self)
        self.cb.move(200, 130)
        self.cb.toggle() #选中
        self.cb.stateChanged.connect(self.changeTitle)
        
        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('CheckBox')
        self.show()
        
    def changeTitle(self, state):
        #if self.cb.isChecked():    #这个可以主动查询
        if state == Qt.Checked:
            self.setWindowTitle('CheckBox')
        else:
            self.setWindowTitle('No CheckBox')
            
        
if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

